﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace _2015.DataCoresp
{
    public partial class DataCorespHome : System.Web.UI.Page
    {

        string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                DropDownListRemDepartment.DataTextField = "division";
                DropDownListRemovePosition.DataTextField = "vacancy";
                DropDownListRemRoom.DataTextField = "ROOM_NAME";
            }

        }

        protected void ButtonAdd_Click(object sender, EventArgs e)
        {

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("spAddVacancy", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Division", DropDownListDepartment.SelectedValue);
                cmd.Parameters.AddWithValue("@UpdatedAdmin", DropDownListUpdatedAdmin.SelectedValue);
                cmd.Parameters.AddWithValue("@Vacancy", TextBoxAddPosition.Text);
                con.Open();
                cmd.ExecuteNonQuery();
            }

        }

        protected void ButtonRemove_Click(object sender, EventArgs e)
        {

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("spRemoveVacancy", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Division", DropDownListRemDepartment.SelectedValue);
                cmd.Parameters.AddWithValue("@Vacancy", DropDownListRemovePosition.SelectedValue);

                con.Open();
                cmd.ExecuteNonQuery();
            }

        }

        protected void ButtonAddRoom_Click(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("spAddRoom", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@RoomCode", TextBoxRoomCode.Text);
                cmd.Parameters.AddWithValue("@RoomName", TextBoxRoomName.Text);
                cmd.Parameters.AddWithValue("@NoOfSeats", TextBoxSeats.Text);
                cmd.Parameters.AddWithValue("@AC", TextBoxAC.Text);
                cmd.Parameters.AddWithValue("@Fans", TextBoxFans.Text);
                cmd.Parameters.AddWithValue("@Lights", TextBoxLights.Text);
                con.Open();
                cmd.ExecuteNonQuery();
            }
        }

        protected void ButtonRemoveRoom_Click(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("spRemRoom", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@RoomCode", DropDownListRemRoom.SelectedValue);
                con.Open();
                cmd.ExecuteNonQuery();
            }
        }

        protected void ButtonExistingVacancy_Click(object sender, EventArgs e)
        {
            Response.Redirect("ViewVacancy.aspx");
        }




    }
}